﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.XPath;
using AutoFolders.Providers;

namespace AutoFolders
{
    public class XsltExtensionLibrary
    {
        public static string NiceUrl(int pageId)
        {
            AutoFolderSetting autoFolderSetting = null;

            XPathNodeIterator pageNode = umbraco.library.GetXmlNodeById(pageId.ToString());
            if (pageNode != null)
            {
                string docType = pageNode.Current.GetAttribute("nodeTypeAlias", "");

                autoFolderSetting = AutoFolderSettings.Instance.GetSettings(docType);
            }

            if (autoFolderSetting != null)
            {
                return autoFolderSetting.FolderProvider.NiceUrl(umbraco.library.NiceUrl(pageId));
            }
            else
            {
                return umbraco.library.NiceUrl(pageId);
            }
        }
    }
}
